// $Id: FileIO.h 78 2007-11-11 21:17:49Z wimleers $


/**
 * FileIO template class header file.
 *
 * @file FileIO.h
 * @author Wim Leers
 */


#ifndef FILEIO_H
#define FILEIO_H

#include <iostream>
#include <fstream>
#include <string>
#include <queue>
using namespace std;

enum Format { FORMAT_CSV };

#define FILEIO_ROW deque<string>
#define FILEIO_TABLE deque< FILEIO_ROW >

class FileIO {
	public:
		FileIO(string fileName = "db", Format f = FORMAT_CSV) { m_fileName = fileName; m_format = f; }
		~FileIO(void) {}
		Format GetFormat(void) const { return m_format; }
		void SetFormat(Format f) { m_format = f; }
		string GetFileName(void) const { return m_fileName; }
		void SetFileName(string fileName) { m_fileName = fileName; }
		FILEIO_TABLE GetTable(void) const { return m_table; }
		void SetTable(FILEIO_TABLE table ) { m_table = table; }
		void Open(void);
		void Save(void);
		void Erase(void);
	private:
		Format m_format;
		string m_fileName;
		FILEIO_TABLE m_table;
		FILEIO_ROW csvReadRow(ifstream & fs);
		void cvsWriteRow(ofstream & fs, FILEIO_ROW row);
};

#endif
